package com.example.mydesignmodule.zhujie;

import java.lang.reflect.Method;

/**
 * @author tgw
 * @date 2021/3/2
 * @describe
 */
class ZhuJieRunMain {

    private static String name;
    private static int id;

    public static void main(String[] args) {

        System.out.println("默认的注解方法值name:" + name + "--id:" + id);
        //赋值
        getAnnonationClass(ZhuJieRunMain.class);
        testAnnonationMethod();
    }

    /**
     * 运行时注解
     */
    @TestAnnonation(name = "tgw注解", id = 3)
    private static void testAnnonationMethod() {
        System.out.println("注解方法赋值name:" + name + "--id:" + id);
    }

    private static void getAnnonationClass(Class clazz) {
        Method[] methods = clazz.getDeclaredMethods();
        for (Method method : methods) {
            TestAnnonation testAnnonation = method.getAnnotation(TestAnnonation.class);
            if (testAnnonation != null) {
                name = testAnnonation.name();
                id = testAnnonation.id();
            }
        }
    }
}
